import os

root_dir = "D:\\python\\python_for_analysis\\pytorch\\hymenoptera_data\\train"
target_dir = "bees_img"
img_list = os.listdir(os.path.join(root_dir, target_dir))
label = target_dir.split('_')[0]
out_dir = "bees_label"
for i in img_list:
    file_name = i.split('.jpg')[0]
    with open(os.path.join(root_dir, out_dir, "{}.txt".format(file_name)), 'w') as f:
        f.write(label)
